<?php

namespace App\Imports;


use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use stdClass;
use App\Models\DeptModel;
use App\Models\AdminRoleModel;

class MaterialImport implements ToCollection, WithMultipleSheets
{


    private $result;

    public function __construct() {
        $this->result = new stdClass;
    }

    public function collection(Collection $rows){
        $lines = [];
        $this->result->error = [];


        foreach ($rows as $k => $row) {
            if($k < 1) continue;

            $lines[] = [
                'name' => $row[0],
                'code' => $row[1],
                'unit' => $row[2],
                'spe' => $row[3],
                'color' => $row[4],
                'limit' => $row[5],
            ];
        }

        $this->result->lines = $lines;
    }

    public function sheets(): array {
        return [ 0 => $this];
    }

    public function get_result(){
        return $this->result;
    }


}
